package gunPowderMod;

import java.util.ArrayList;
import java.util.List;

import gunPowderMod.block.Fuse;
import gunPowderMod.block.MiningDynamite;
import gunPowderMod.entities.MiningDynamitePrimed;
import gunPowderMod.entities.renderer.MiningDynamitePrimedRenderer;
import gunPowderMod.items.RefinedGunPowder;
import gunPowderMod.network.CommonProxy;
import gunPowderMod.network.PacketHandler;
import gunPowderMod.recipes.FuseRecipe;
import gunPowderMod.recipes.MiningDynamiteRecipe;

import net.minecraft.src.IBlockAccess;
import net.minecraft.src.ItemMapBase;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Item;
import net.minecraft.src.Block;
import net.minecraft.src.RenderManager;
import net.minecraft.src.ShapelessRecipes;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.Property;

import org.lwjgl.util.glu.Registry;

import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.*;
import cpw.mods.fml.common.Mod.*;
import cpw.mods.fml.common.event.*;
import cpw.mods.fml.common.network.*;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.EntityRegistry.EntityRegistration;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = "TrizzelnovasGunPowderMod", name = "Gun Powder Mod", version = "0.1.0")
@NetworkMod(clientSideRequired = true, serverSideRequired = true, versionBounds = "[0.1.0]", packetHandler = PacketHandler.class)
public class GunPowderMod {

	private Configuration config;

	// block instances
	public static Fuse fuseBlock;
	public static MiningDynamite miningDynamiteBlock;

	// item instances
	public static RefinedGunPowder refinedGunPowder;

	public static final String blockTexturePath = "/gunPowderMod/texture/blocks.png";
	public static final String itemTexturePath = "/gunPowderMod/texture/items.png";

	@Instance("TrizzelnovasGunPowderMod")
	public static GunPowderMod instance;

	@SidedProxy(clientSide = "gunPowderMod.network.ClientProxy", serverSide = "gunPowderMod.network.CommonProxy")
	public static CommonProxy proxy;

	@PreInit
	public void preInit(FMLPreInitializationEvent event) {
		config = new Configuration(event.getSuggestedConfigurationFile());
		config.load();
	}

	@Init
	public void init(FMLInitializationEvent event) {
		// register render information
		proxy.registerRenderInformation();

		// SetUp Blocks

		// Mining Dynamite
		Property miningDynamiteIDProperty = config.getBlock(Configuration.CATEGORY_BLOCK, "miningDynamiteBlockID", 1501);
		miningDynamiteIDProperty.comment = "The blockID of the Mining Dynamite block";
		miningDynamiteBlock = new MiningDynamite(miningDynamiteIDProperty.getInt());
		LanguageRegistry.addName(miningDynamiteBlock, "Mining Dynamite");
		GameRegistry.registerBlock(miningDynamiteBlock);
		EntityRegistry.registerModEntity(MiningDynamitePrimed.class, "miningDynamitePrimed", 1, this, 250, 20, true);

		// Fuse:
		Property fuseBlockIDProperty = config.getBlock(Configuration.CATEGORY_BLOCK, "fuseBlockID", 1500);
		fuseBlockIDProperty.comment = "The blockID of the Fuse block";
		fuseBlock = new Fuse(fuseBlockIDProperty.getInt());
		LanguageRegistry.addName(fuseBlock, "Fuse");
		GameRegistry.registerBlock(fuseBlock);

		// Setup Items
		//Refined Gunpowder
		Property refinedGunPowderIDProperty = config.getItem(Configuration.CATEGORY_ITEM, "refinedGunPowderID", 1550);
		refinedGunPowderIDProperty.comment = "The itemID of the refined gun powder";
		refinedGunPowder = new RefinedGunPowder(refinedGunPowderIDProperty.getInt());
		LanguageRegistry.addName(refinedGunPowder, "Refined Gun Powder");

		registerRecipes();
	}
	
	private static void registerRecipes() {
		// Register Recipes
		// Blocks
		GameRegistry.addRecipe(new FuseRecipe());
		GameRegistry.addRecipe(new MiningDynamiteRecipe());
		
		//Items
		List recipeList = new ArrayList();
		recipeList.add(new ItemStack(Item.sugar, 1));
		recipeList.add(new ItemStack(Item.coal, 1, 1));
		recipeList.add(new ItemStack(Item.gunpowder, 1));
		recipeList.add(new ItemStack(Item.gunpowder, 1));
		GameRegistry.addRecipe(new ShapelessRecipes(new ItemStack(GunPowderMod.refinedGunPowder), recipeList));
	}
	
	@PostInit
	public void postInit(FMLPostInitializationEvent event) {
		config.save();
	}

}
